package net.huanger.gametools.mapeditor.ui;


import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JComponent;


public class MapCanvas extends JComponent
{
  private static final long serialVersionUID = 1L;

  private MapEditorPanel mapEditroPanel;

  public MapCanvas(MapEditorPanel mapEditorPanel)
  {
    this.mapEditroPanel = mapEditorPanel;
    init();
  }

  private void init()
  {
    initEventListener();
  }

  private void initEventListener()
  {
    this.addMouseListener(new MouseAdapter()
      {

        @Override
        public void mouseClicked(MouseEvent e)
        {
          OperateContext oc = mapEditroPanel.getOperateContext();
          if (oc != null)
          {
            oc.mapClick(e);
          }
        }
      });
  }

  @Override
  protected void paintComponent(Graphics g)
  {
    //    super.paintComponent(g);
    OperateContext oc = mapEditroPanel.getOperateContext();
    if (oc != null)
    {
      for (Operate o : oc.getAllOperates())
      {
        IDiv mapDiv = o.getMapDiv();
        if (mapDiv.isShow())
        {
          mapDiv.drawDiv(g);
        }
      }
    }
  }
}
